package cate.game.role.show.avatar;


import cate.common.table.d.GDBlog;
import cate.common.table.show.row.AvartarRow;
import cate.game.role.show.ShowBagTab;
import cate.game.role.show.msg.ModifyAvatarResp;
import easy.java.dev.note.NoteClass;

import java.util.List;


@NoteClass("冒险形象")
public class RoleAvatar extends ShowBagTab<Avatar> {


    @Override
    public byte getType() {
        return GDBlog.DecorateType.AVATAR;
    }

    @Override
    protected Avatar createItem(int tid, long validTime) {
        return new Avatar(tid,validTime);
    }

    @Override
    public void onCreate() {
        role.getBase().avatar.tid = findDefaultTid();
    }

    public int findDefaultTid() {
        AvartarRow defaultRow = role.getGame().table.blog.avartar.findDefaultRow(role.getBase().sex);
        if (defaultRow != null) {
            return defaultRow.tid;
        } else {
            return 0;
        }
    }

    @Override
    public void onInvalid(List<Integer> expireTids) {
        for (Integer expireTid : expireTids) {
            if (role.getBase().avatar.tid == expireTid) {
                role.getBase().avatar.tid = findDefaultTid();
                role.sendNow(new ModifyAvatarResp(role));
                return;
            }
        }
    }


    @Override
    public boolean isActive(int tid) {
        AvartarRow row = role.getGame().table.blog.avartar.get(tid);
        if (row == null) {
            return false;
        }
        switch (row.activeType) {
            case GDBlog.ActiveType.HERO:
                return role.getRes().heroIntroduction.heroProtoGots.contains(row.value);
            case GDBlog.ActiveType.VIP:
                return role.getBase().vip >= row.value;
            case GDBlog.ActiveType.HERO_SKIN:
                return role.getShow().heroSkin.getItem(row.value) != null;
            case GDBlog.ActiveType.ITEM:
                return getItem(tid) != null;
            case GDBlog.ActiveType.SEX:
                return true;
            case GDBlog.ActiveType.LEADER_SKIN:
                return role.getShow().leaderSkin.getItem(row.value) != null;
            default:
                return false;
        }
    }


}
